#include "CSpecialEnemy.h"

CSpecialEnemy::CSpecialEnemy()
{
	SetAlive(true);
	SetPassive(true);;
	SetDistanceToPlayer(VIN_Vector2D(0.0f, 0.0f));
	SetHP(110);
	SetPower(20);
}

CSpecialEnemy::~CSpecialEnemy()
{

}

void CSpecialEnemy::Attack()
{
	// TODO: Attack the player by deciding on what range they are in. if they are in longer range, behave same as ranged AI
	// If they are close behave same as melee AI. The attack cooldown is 4 seconds
}

void CSpecialEnemy::HurtMe()
{
	SetHP(GetHP() - ( RandInt(20, 30) + (CHubState::GetInstance()->GetPlayer()->GetCombat() * 4)));
	if(GetHP() <= 0)
	{
		// TODO: Kill the enemy and increase the player's money by a random amount
		// Play enemy death sound
	}
}

void CSpecialEnemy::Update( float fElapsedTime)
{
	static float attacktimer = 0.0f;
	attacktimer += fElapsedTime;
	// TODO move around the screen towards the player and away from the player
	// m_vDistanceToPlayer.m_fX = GetPosX() - CHubState::GetInstance()->GetPlayer()->GetPosX();
	// m_vDistanceToPlayer.m_fY = GetPosY() - CHubState::GetInstance()->GetPlayer()->GetPosY();

	SetDistanceToPlayer(VIN_Vector2D(GetPosX() - CHubState::GetInstance()->GetPlayer()->GetPosX(), GetPosY() - CHubState::GetInstance()->GetPlayer()->GetPosY()));

	if(attacktimer >= 4.0f)
	{
		SetVelX(0.0f);
		SetVelY(0.0f);

		Attack();
		attacktimer = 0.f;
	}
	else
	{
		if(GetPosX() > CHubState::GetInstance()->GetPlayer()->GetPosX())
		{
			SetVelX(-50.0f);
		}
		else
		{
			SetVelX(50.0f);

		}
		if(GetPosY() > CHubState::GetInstance()->GetPlayer()->GetPosY())
		{
			SetVelY(-10.0f);
		}
		else
		{
			SetVelY(10.0f);
		}
	}

	SetPosX(GetPosX() + (GetVelX() * fElapsedTime));
	SetPosY(GetPosY() + (GetVelY() * fElapsedTime));
}

void CSpecialEnemy::Render()
{

}